<!--
 * @Descripttion:
 * @version:
 * @Author: cxguo
 * @Date: 2020-08-03 07:51:09
 * @LastEditors: cxguo
 * @LastEditTime: 2020-11-07 14:14:36
-->
<template>
  <div>
    <vxe-grid
      ref="table"
      class="grid"
      border
      resizable
      highlight-hover-row
      :loading="loading"
      :columns="columnsData"
      :data="tableData"
    />
  </div>
</template>

<script>
import { listDataGroupByGoods } from '@/api/report/purchase.js'
import { getLast7DaysRange } from '@/libs/date.js'

export default {
  data() {
    return {
      loading: false,
      columnsData: [
        { title: '序号', type: 'seq', width: 60, align: 'center' },
        { field: 'code', title: '商品编号', width: 140 },
        { field: 'name', title: '商品名称', width: 200 },
        { field: 'amountPayable', title: '进货额', align: 'right', width: 140 }
      ],
      pageInfo: {
        current: 1, // 当前页
        size: 20, // 每页数据条数
        sort: '', // 排序字段
        order: 'desc', // 排序方向
        total: 0 // 总数居量
      },
      tableData: []
    }
  },
  created() {
    this.initData()
  },
  methods: {
    initData() {
      const params = {
        data: getLast7DaysRange(),
        page: this.pageInfo
      }
      listDataGroupByGoods(params).then(res => {
        if (!res.data.flag) return
        const { records, total } = res.data.data
        this.tableData = records
        this.pageInfo.total = total
      })
    }
  }
}
</script>

<style>

</style>
